package com.shimao.celnet.payment.service.impl;


import com.shimao.celnet.payment.model.PInvoiceBlueDetail;
import com.shimao.celnet.payment.service.PInvoiceBlueDetailService;
import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class PInvoiceBlueDetailServiceImpl extends BaseServiceImpl<PInvoiceBlueDetail> implements PInvoiceBlueDetailService {

    protected Logger logger = Logger.getLogger(this.getClass());

    /**
     * 根据蓝票guid，查询开票明细
     * @param invoiceGuid:蓝票guid
     * @return
     */
    @Override
    public List<PInvoiceBlueDetail> getByInvoiceGuid(String invoiceGuid){
        Example example = new Example(PInvoiceBlueDetail.class);
        Example.Criteria criteria = example.createCriteria();
        //小区SFID
        criteria.andEqualTo("invoiceGuid", invoiceGuid);
        List<PInvoiceBlueDetail> tableList = getByExample(example);
        if(tableList==null||tableList.size()<=0){
            tableList = getByInvoiceGuid1(invoiceGuid);
        }
        return tableList;
    }
    /**
     * 根据拆票蓝票guid，查询开票明细
     * @param invoiceGuid:蓝票guid
     * @return
     */
    @Override
    public List<PInvoiceBlueDetail> getByInvoiceGuid1(String invoiceGuid) {
        Example example = new Example(PInvoiceBlueDetail.class);
        Example.Criteria criteria = example.createCriteria();
        //小区SFID
        criteria.andEqualTo("newInvoiceGuid", invoiceGuid);
        List<PInvoiceBlueDetail> tableList = getByExample(example);
        return tableList;
    }

    /**
     *新增权限保存
     * @return
     */
    @Override
    public int save(PInvoiceBlueDetail sBean){
        int retCnt=0;
        String loginUserGuid = (String) SecurityUtils.getSubject().getSession().getAttribute("userSessionId");
        sBean.setUpdateUserGuid(loginUserGuid);
        sBean.setCreatedUserGuid(loginUserGuid);
        sBean.setGuid(getGuid());//guid
        retCnt = super.save(sBean);

        return retCnt;
    }

    /**
     *修改权限保存
     * @return
     */
    @Override
    public int update(PInvoiceBlueDetail sBean){
        String loginUserGuid = (String) SecurityUtils.getSubject().getSession().getAttribute("userSessionId");
        sBean.setUpdateUserGuid(loginUserGuid);
        int retCnt = super.update(sBean);

        return retCnt;
    }
}
